package cn.crism.controller;

import cn.crism.commons.JsonData;
import cn.crism.dto.DeptLevelDto;
import cn.crism.param.DeptParam;
import cn.crism.service.SysDeptService;
import cn.crism.service.SysTreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @CreateDate: 2018/12/13 3:34 PM
 * @Description:
 * @Author: Crism
 */
@Controller
@RequestMapping("/sys/dept")
@Slf4j
public class SysDeptController {

    @Resource
    private SysDeptService sysDeptService;
    @Resource
    private SysTreeService sysTreeService;

    @RequestMapping("/dept_view.v")
    public ModelAndView deptView(){
        return new ModelAndView("/Light/index");
    }


    @RequestMapping("/save.m")
    @ResponseBody
    public JsonData saveDept(DeptParam param){
        sysDeptService.saveDept(param);
        return JsonData.success();
    }

    @RequestMapping("/dept_tree.m")
    @ResponseBody
    public JsonData deptTree(){
        List<DeptLevelDto> dtoList = sysTreeService.deptTree();
        return JsonData.success(dtoList);
    }

    @RequestMapping("/update_dept.m")
    @ResponseBody
    public JsonData updateDept(DeptParam param){
        sysDeptService.updateDept(param);
        return JsonData.success();
    }
}
